import java.util.ArrayList;
import java.util.List;

import org.apache.mina.core.buffer.IoBuffer;


public class RadiusPacket {
	
	
	private static int RAD_HEADER_LENGTH = 20;
	
	public static int MAX_PACKET_LENGTH = 4096;
	
	public static int MIN_PACKET_LENGTH = 20;

	private int code;
	
	private int identifier;
	
	private int length;
	
	private byte[] auth = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16};
	
	private List<RadiusAttribute> avpList = new ArrayList<>();
	
	public void addRadiusAttribute(RadiusAttribute attr) {
		avpList.add(attr);
	}
	
	public void setCommandCode(int commandCode) {
		code = commandCode;
	}
	
	
	
	public int getIdentifier() {
		/*
		 * this part is here temporarily for testing purpose
		 * identifer should be created according to RFC #2865
		 */
		identifier = 76;
		return identifier;
	}

	public void setIdentifier(int identifier) {
		this.identifier = identifier;
	}

	public int getLength() {
		return calculateLength();
	}

	public void setLength(int length) {
		this.length = length;
	}

	public byte[] getAuth() {
		/*
		 * this part is here temporarily for testing purpose
		 * authenticator should be created according to RFC #2865
		 */

		return auth;
	}

	public void setAuth(byte[] auth) {
		this.auth = auth;
	}

	public int getCode() {
		return code;
	}

	public List<RadiusAttribute> getAvpList() {
		return avpList;
	}
	
	private int calculateLength() {
		int length = RAD_HEADER_LENGTH;
		for (RadiusAttribute attr : avpList) {
			length += attr.getLength();
		}
		return length;
	}
}
